*************************************************************************************
*****			Please cite Georgiadou et al. (2018) as indicated in 			*****
*****  	https://www.sciencedirect.com/science/article/pii/S026137941830026X		*****
*************************************************************************************
**** Code adapted after Golder 2003  *****


use Data/GRR_data.dta, clear
cd Graphs


***** Original code from Golder (2003), adapted for our regressions
 gen _Zero = 0

*******************
*   Figure A3 a   *
*******************
estat vce
generate JH=((_n-1)/1000)    
replace JH=. if _n>250
generate str1 txt="*"

scalar b1= .012658 
scalar b2= 4.317404 
scalar b3=  -.1400457
scalar varb1= 6.133e-06 
scalar varb3= .00114579
scalar covb1b3=  -.00003983 

set more off
*scalar list b1 b2 b3 varb1 varb3 covb1b3

*     ****************************************************************  *
*      Except for in left hand side of following, do search and replace *
*      for JH below                                                     *
*     ****************************************************************  *

gen conb=b1+b3*JH if _n<260
set more off
list conb in 1/20

*     ****************************************************************  *
*      These create conditional coefficients for b1 at JH, x3H#         *
*     ****************************************************************  *
*      We can write the following code as a template, then sub in the   *
*      names of the "variables" for JH *x3 .   "variables" because they *
*      won't be the real variables.  Instead, they'll be the variables  *
*      created to represent the relevant values of the modifying        *
*      variables.                                                       *
*     ****************************************************************  *

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<260
set more off
list conse in 1/20
gen cont= conb/conse
list cont in 1/20

*     ****************************************************************  *
*      This creates a conditional t for each level of JHHH given which  *
*      x3H is chosen                                                    *
*     ****************************************************************  *

gen conbS = conb

*     ****************************************************************  *
*       These create "shadow" (thus the "S") variables for each of the  *
*       conditional b's.  Statistical significance indicated at 95%     *
*       level (one-tailed).                                             *
*     ****************************************************************  *

replace conbS = . if abs(cont)<1.645
list conbS in 1/20

*     ****************************************************************  *
*      This creates missing values for all the insignificant shadow b's.*
*     ****************************************************************  *
*     ****************************************************************  *
*     ****************************************************************  *
*       Generate confidence intervals at the 95% level                  *
*     ****************************************************************  *
*     ****************************************************************  *

gen a=1.645*conse
gen top=conb+a
gen bottom=conb-a
set textsize 100

*     ****************************************************************  *
*       Graph the effect of Immigration  on Voteshare conditional on    *
*       Unemployment                                                    *
*     ****************************************************************  *
gprefs set window scheme blackbg
gprefs set window update
gprefs set custom1 pen2_thick 9

twoway rarea bottom top JH, color(gs12) fcolor(gs12) graphregion(color(white))  legend(off) xtitle("% Uneployment",  size(medlarge)) ytitle("Effect of GDP PPS per habitant on PRR vote", size(small)) saving(figureA3a,replace)|| line conb JH, lcolor(black) || line _Zero JH, lcolor(black) lpattern(dash) lwidth(med)



drop txt JH txt conb conse cont conbS a top bottom









*******************
*   Figure A3 b   *
*******************
 
*** run regression obtain coefficients (Unemployment GDP interaction)
pantob PRR Lunemp Lgdp_pps_hab Lunemp_gdp Ldiff_immigration Ltax Lgini  Lwage_sh LD_gdp_growth    D_par  nuts_2 
*** get variance-covariance matrix
estat vce
generate JH=((_n-1)/100)    
replace JH=. if _n>2000

generate str1 txt="*"
scalar b1= 4.317404 
scalar b2= .012658   
scalar b3=  -.1400457
scalar varb1= .30656573
scalar varb3= .00114579
scalar covb1b3=  .30656573 
set more off

*scalar list b1 b2 b3 varb1 varb3 covb1b3

*     ****************************************************************  *
*      Except for in left hand side of following, do search and replace *
*      for JH below                                                     *
*     ****************************************************************  *

gen conb=b1+b3*JH if _n<2000

set more off

*list conb in 1/20

*     ****************************************************************  *
*      These create conditional coefficients for b1 at JH, x3H#         *
*     ****************************************************************  *
*      We can write the following code as a template, then sub in the   *
*      names of the "variables" for JH *x3 .   "variables" because they *
*      won't be the real variables.  Instead, they'll be the variables  *
*      created to represent the relevant values of the modifying        *
*      variables.                                                       *
*     ****************************************************************  *


gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<2000
set more off
list conse in 1/20
gen cont= conb/conse
list cont in 1/20

*     ****************************************************************  *
*      This creates a conditional t for each level of JHHH given which  *
*      x3H is chosen                                                    *
*     ****************************************************************  *

gen conbS = conb

*     ****************************************************************  *
*       These create "shadow" (thus the "S") variables for each of the  *
*       conditional b's.  Statistical significance indicated at 95%     *
*       level (one-tailed).                                             *
*     ****************************************************************  *

replace conbS = . if abs(cont)<1.645
list conbS in 1/20

*     ****************************************************************  *
*      This creates missing values for all the insignificant shadow b's.*
*     ****************************************************************  *
*     ****************************************************************  *
*     ****************************************************************  *
*       Generate confidence intervals at the 95% level                  *
*     ****************************************************************  *
*     ****************************************************************  *

gen a=1.645*conse
gen top=conb+a
gen bottom=conb-a
set textsize 100

*     ****************************************************************  *
*       Graph the effect of Immigration  on Voteshare conditional on    *
*       Unemployment                                                    *
*     ****************************************************************  *
gprefs set window scheme blackbg
gprefs set window update
gprefs set custom1 pen2_thick 9

twoway rarea bottom top JH, color(gs12) fcolor(gs12) graphregion(color(white))  legend(off) xtitle("GDP PPS per habitant",  size(medlarge)) ytitle("Effect of unemployment on PRR vote", size(small)) saving(figureA3b,replace)  || line conb JH, lcolor(black) || line _Zero JH, lcolor(black) lpattern(dash) lwidth(med)



drop  JH txt conb conse cont conbS a top bottom































*******************
*   Figure A3 c   *
*******************
estat vce



generate JH=((_n-1)/1000)    

replace JH=. if _n>250




generate str1 txt="*"


scalar b1= .0058671
scalar b2=  1.232266  
scalar b3= .0108895 

scalar varb1=  7.955e-06
scalar varb3= .00081484
scalar covb1b3=  -.0000409 






set more off

scalar list b1 b2 b3 varb1 varb3 covb1b3

*     ****************************************************************  *
*      Except for in left hand side of following, do search and replace *
*      for JH below                                                     *
*     ****************************************************************  *

gen conb=b1+b3*JH if _n<260

set more off

list conb in 1/20

*     ****************************************************************  *
*      These create conditional coefficients for b1 at JH, x3H#         *
*     ****************************************************************  *
*      We can write the following code as a template, then sub in the   *
*      names of the "variables" for JH *x3 .   "variables" because they *
*      won't be the real variables.  Instead, they'll be the variables  *
*      created to represent the relevant values of the modifying        *
*      variables.                                                       *
*     ****************************************************************  *


gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<260
set more off

list conse in 1/20
gen cont= conb/conse

list cont in 1/20

*     ****************************************************************  *
*      This creates a conditional t for each level of JHHH given which  *
*      x3H is chosen                                                    *
*     ****************************************************************  *

gen conbS = conb

*     ****************************************************************  *
*       These create "shadow" (thus the "S") variables for each of the  *
*       conditional b's.  Statistical significance indicated at 95%     *
*       level (one-tailed).                                             *
*     ****************************************************************  *

replace conbS = . if abs(cont)<1.645

list conbS in 1/20

*     ****************************************************************  *
*      This creates missing values for all the insignificant shadow b's.*
*     ****************************************************************  *
*     ****************************************************************  *
*     ****************************************************************  *
*       Generate confidence intervals at the 95% level                  *
*     ****************************************************************  *
*     ****************************************************************  *

gen a=1.645*conse
gen top=conb+a
gen bottom=conb-a

set textsize 100

*     ****************************************************************  *
*       Graph the effect of Immigration  on Voteshare conditional on    *
*       Unemployment                                                    *
*     ****************************************************************  *
gprefs set window scheme blackbg
gprefs set window update
gprefs set custom1 pen2_thick 9

twoway rarea bottom top JH, color(gs12) fcolor(gs12) graphregion(color(white))  legend(off) xtitle("% Uneployment",  size(medlarge)) ytitle("Effect of GDP PPS per habitant on ER vote", size(small)) saving(figureA3c,replace) || line conb JH, lcolor(black) || line _Zero JH, lcolor(black) lpattern(dash) lwidth(med)

drop JH txt conb conse cont conbS a top bottom




*******************
*   Figure A3 d   *
*******************
*** run regression obtain coefficients (Unemployment GDP interaction)
pantob ext_right_cat1 Lunemp Lgdp_pps_hab Lunemp_gdp Ldiff_immigration Ltax Lgini  Lwage_sh LD_gdp_growth    D_par  nuts_2 
*** get variance-covariance matrix
estat vce



generate JH=((_n-1)/100)    

replace JH=. if _n>2000




generate str1 txt="*"


scalar b1= 1.232266 
scalar b2=  .0058671   
scalar b3=  .0108895

scalar varb1=  .36355827 
scalar varb3= .00081484 
scalar covb1b3=   -.01439257






set more off

scalar list b1 b2 b3 varb1 varb3 covb1b3

*     ****************************************************************  *
*      Except for in left hand side of following, do search and replace *
*      for JH below                                                     *
*     ****************************************************************  *

gen conb=b1+b3*JH if _n<2000

set more off

list conb in 1/20

*     ****************************************************************  *
*      These create conditional coefficients for b1 at JH, x3H#         *
*     ****************************************************************  *
*      We can write the following code as a template, then sub in the   *
*      names of the "variables" for JH *x3 .   "variables" because they *
*      won't be the real variables.  Instead, they'll be the variables  *
*      created to represent the relevant values of the modifying        *
*      variables.                                                       *
*     ****************************************************************  *


gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<2000
set more off

list conse in 1/20
gen cont= conb/conse

list cont in 1/20

*     ****************************************************************  *
*      This creates a conditional t for each level of JHHH given which  *
*      x3H is chosen                                                    *
*     ****************************************************************  *

gen conbS = conb

*     ****************************************************************  *
*       These create "shadow" (thus the "S") variables for each of the  *
*       conditional b's.  Statistical significance indicated at 95%     *
*       level (one-tailed).                                             *
*     ****************************************************************  *

replace conbS = . if abs(cont)<1.645

list conbS in 1/20

*     ****************************************************************  *
*      This creates missing values for all the insignificant shadow b's.*
*     ****************************************************************  *
*     ****************************************************************  *
*     ****************************************************************  *
*       Generate confidence intervals at the 95% level                  *
*     ****************************************************************  *
*     ****************************************************************  *

gen a=1.645*conse
gen top=conb+a
gen bottom=conb-a

set textsize 100

*     ****************************************************************  *
*       Graph the effect of Immigration  on Voteshare conditional on    *
*       Unemployment                                                    *
*     ****************************************************************  *
gprefs set window scheme blackbg
gprefs set window update
gprefs set custom1 pen2_thick 9


twoway rarea bottom top JH, color(gs12) fcolor(gs12) graphregion(color(white))  legend(off) xtitle("GDP PPS per habitant",  size(medlarge)) ytitle("Effect of unemployment on ER vote", size(small)) saving(figureA3d,replace) || line conb JH, lcolor(black) || line _Zero JH, lcolor(black) lpattern(dash) lwidth(med)
drop txt JH txt conb conse cont conbS a top bottom

gr combine figureA3a.gph figureA3b.gph figureA3c.gph figureA3d.gph, graphregion(color(white))


graph save ../Graphs/FigureA3.gph, replace
graph export ../Graphs/FigureA3.pdf, replace

cd ..



